package com.ge.healthcare.autosc.common.util;

/**
 * Title:  FileComparisonResult
 * Description:  Describes the result of a file comparison.
 *
 * Copyright:    Copyright (c) 2000
 * Company:  GEMS
 * @author  MDK
 * @version 1.0
 */
public class FileComparisonResult
{
    /**
     * Construct a result with a string "window".
     * @param isEqual true if both files are equal.
     * @param firstDiffIndex the index into the file where the first difference occurs.
     * @param diffWindow1 the window around the difference for the first file.
     * @param diffWindow2 the window around the difference for the second file.
     */
    FileComparisonResult(boolean isEqual, long firstDiffIndex,
                         String diffWindow1, String diffWindow2)
    {
        isEqual_ = isEqual;
        firstDiffIndex_ = firstDiffIndex;
        diffWindow1_ = diffWindow1;
        diffWindow2_ = diffWindow2;
    }

    /**
     * Construct a result with a binary "window".
     * @param isEqual true if both files are equal.
     * @param firstDiffIndex the index into the file where the first difference occurs.
     * @param diffWindow1 the window around the difference for the first file.
     * @param diffWindow2 the window around the difference for the second file.
     */
    FileComparisonResult(boolean isEqual, long firstDiffIndex,
                         byte[] diffWindow1, byte[] diffWindow2)
    {
        isEqual_ = isEqual;
        firstDiffIndex_ = firstDiffIndex;
        diffWindow1_ = byteArrayToByteString(diffWindow1);
        diffWindow2_ = byteArrayToByteString(diffWindow2);
    }

    /**
     * Returns the boolean comparison result.
     * @return true if the files are equal.
     */
    public boolean isEqual()
    {
        return isEqual_;
    }

    /**
     * Returns the index where the first difference occurs between the files.
     * @return the first difference index.
     */
    public long firstDiffIndex()
    {
        return firstDiffIndex_;
    }

    /**
     * Returns the difference window for the first file where the difference between
     * the files occurs.
     * @return the first difference window.
     */
    public String diffWindow1()
    {
        return diffWindow1_;
    }

    /**
     * Returns the difference window for the second file where the difference between
     * the files occurs.
     * @return the second difference window.
     */
    public String diffWindow2()
    {
        return diffWindow2_;
    }

    /**
     * Converts an array of bytes into a displayable string.
     * @param buffer the buffer of bytes.
     * @return the display string.
     */
    private String byteArrayToByteString(byte[] buffer)
    {
        StringBuffer result = new StringBuffer();

        for (int i = 0; i < buffer.length; i++)
        {
            result.append(Byte.toString(buffer[i]));
        }

        return result.toString();
    }

    /** Boolean indicating file equivelance (or not). */
    private boolean isEqual_;

    /** Index of the first difference between files. */
    private long firstDiffIndex_;

    /** The difference window for file 1. */
    private String diffWindow1_;

    /** The difference window for file 1. */
    private String diffWindow2_;
}
